/*
	Callbacks.c
	--------------------------------------------------
	Squirrel event handlers.
*/

#include "Callbacks.h"
#include "Functions.h"
#include "SQMain.h"
#include <stdio.h>

LU_RETURN PlayerConnect( Player player )
{
	return LU_OK;
}

LU_RETURN PlayerJoin( Player player )
{
	int id = 0;
	char name[ MAX_NAME_LEN+1 ] = { 0 };
	char ip[ 15 ] = { 0 };
	char message[ 128 ] = { 0 };
	Colour col_blue;
	Colour col_yellow;

	col_blue.r = 100; col_blue.g = 100; col_blue.b = 255;
	col_yellow.r = 255; col_yellow.g = 255; col_yellow.b = 0;
	
	GetPlayerID( player, &id );
	GetPlayerName( player, name );
	GetPlayerIP( player, ip );

	sprintf( message, "* [%u] %s joined the server (IP: %s)", id, name, ip );
	Message( message, col_blue );

	sprintf( message, "Welcome to the server, %s!", name );
	MessagePlayer( message, player, col_yellow );

	return LU_OK;
}

LU_RETURN PlayerPart( Player player, unsigned char reason )
{
	return LU_OK;
}

LU_RETURN PlayerSpawn( Player player, SpawnClass spawn )
{
	float health = 0.0;
	char message[ 128 ] = { 0 };
	Vector3 pos;
	Colour col_white; col_white.r = 255; col_white.g = 255; col_white.b = 255;
	
	GetPlayerHealth( player, &health );

	sprintf( message, "Your health is %u.", health );
	MessagePlayer( message, player, col_white );

	SetPlayerHealth( player, 50 );
	MessagePlayer( "And now it isn't!", player, col_white );

	// Slap on spawn, how evil is that
	GetPlayerPos( player, &pos );
	pos.z += 10.0f;
	SetPlayerPos( player, &pos );

	return LU_OK;
}
